using System;
using System.Collections.Generic;
using System.Text;
using Ghasam.Business.Domain.Entity;
using Ghasam.Business.DTO;
using Ghasam.Business.DAO;
using System.Collections;
using Spring.Transaction.Interceptor;
namespace Ghasam.Business.Services.Impl
{
    public class StockService:IStockService
    {
        #region "Private Method"

        private IStockDao iStockDao;
        private IStockStatusDao iStockStatusDao;
        private IStockHistoryDao iStockHistoryDao;
        private IUsageDescriptionDao iUsageDescriptionDao;
        #endregion
        #region "Public Method"

        public IStockDao IStockDao
        {
            get { return iStockDao; }
            set { iStockDao = value; }
        }
        public IStockStatusDao IStockStatusDao
        {
            get { return iStockStatusDao; }
            set { iStockStatusDao = value; }
        }
        public IStockHistoryDao IStockHistoryDao
        {
            get { return iStockHistoryDao; }
            set { iStockHistoryDao = value; }
        }
        public IUsageDescriptionDao IUsageDescriptionDao
        {
            get { return iUsageDescriptionDao; }
            set { iUsageDescriptionDao = value; }
        }

        public IList<Stock> FindAll()
        {
            IList<Stock> stock = IStockDao.FindAll();

            return stock;
        }
        public IList<StockStatus> FindAllState()
        {
            IList<StockStatus> StockState = IStockStatusDao.FindAll();

            return StockState;
        }
        public IList<Stock> FindStock(string name, string binnumber, string serial, int? status, DateTime? importdate, int pageSize, int pageNo)
        {
            return IStockDao.FindStock(name, binnumber,serial,status, importdate,pageSize,pageNo);
        }

        [Transaction(ReadOnly = false)]
        public void StockSaveOrUpadate(string name, string binnumber, string serial, int quantity, int orderPoint, int status, string description, DateTime? importdate, DateTime? modifydate)
        {
            Stock stock = new Stock();
            StockStatus stockStatus = IStockStatusDao.FindById(status);
            stock.StockName = name;
            stock.BinNumber = binnumber;
            stock.Serial = serial;
            stock.Quantity = quantity;
            stock.OrderPoint = orderPoint;
            stock.StockStatus = stockStatus;
            stock.Description = description;
            stock.ImportDate = importdate;
            stock.ModifyStamp = modifydate;
            IStockDao.SaveOrUpdate(stock);
        }

        [Transaction(ReadOnly = false)]
        public void StockHistorySaveOrUpadate(int stockId, int employeeid,int status ,DateTime? exitDate, DateTime? returnDate, string usageDescription, string description, DateTime? modifydate)
        {
            StockHistory stockHistory = new StockHistory();
            Stock stock = IStockDao.FindById(stockId);
            stockHistory.Stock = stock;
            stockHistory.StockStatus = IStockStatusDao.FindById(status);
            stockHistory.ReturnDate = returnDate;
            stockHistory.UsageDescription = usageDescription;
            stockHistory.ExitDate = exitDate;
            stockHistory.EmployeeID = employeeid;
            stockHistory.Description = description;
            stockHistory.ModifyStamp = modifydate;
            IStockHistoryDao.SaveOrUpdate(stockHistory);
        }

        [Transaction(ReadOnly = false)]
        public void StockUpdate(int id, int quantity)
        {
            Stock stock = IStockDao.FindById(id);
            stock.Quantity = quantity;
            stock.Id = id;
            IStockDao.SaveOrUpdate(stock);
        }
        public IList<StockHistory> FindStockHistory(string name, string binnumber, string serial, int? status, int? employeeid, DateTime? exitDate, DateTime? returnDate, int pageSize, int pageNo)
        {
            return IStockHistoryDao.FindStockHistory(name,binnumber,serial,status, employeeid,exitDate,returnDate,pageSize,pageNo);
        }
        public IList<UsageDescription> FindAllDescription()
        {
            return IUsageDescriptionDao.FindAll();
        }
        public IList<Stock> FindOrderPoint()
        {
            return iStockDao.FindOrderPoint();
        }

        [Transaction(ReadOnly = false)]
        public void Delete(int stockid, string name)
        {
            Stock stock = new Stock();
            stock.Id = stockid;
            stock.StockName = name;
            IStockDao.Delete(stock);
        }
        #endregion
    }
}
